#include"stack.h"
void StInit(stack* s)
{
	s->data = (DataType*)malloc(sizeof(DataType) * CAPCITY_MULTIPLY);
	if (s->data == NULL)
	{
		perror("malloc");
		return;
	}
	s->capcity = CAPCITY_INIT;
	s->size = 0;
}

void StDestory(stack* s)
{
	free(s->data);
	s->data = NULL;
	s->capcity = 0;
	s->size = 0;
}

bool StCheck(stack* s)
{
	return s->capcity == s->size;
}

void StEnlarge(stack* s)
{
	DataType* tmp = (DataType*)realloc(s->data, sizeof(DataType) * s->capcity * CAPCITY_MULTIPLY);
	if (tmp == NULL)
	{
		perror("realloc");
		return;
	}
	s->data = tmp;
	s->capcity *= CAPCITY_MULTIPLY;
}
void StPush(stack* s, DataType x)
{
	if (StCheck(s))
		StEnlarge(s);
	s->data[s->size++] = x;
}
void StPop(stack* s)
{
	assert(!STEmpty(s));
	s->size--;
}

DataType StTop(stack* s)
{
	assert(s);
	assert(!STEmpty(s));
	return s->data[s->size-1];
}

bool STEmpty(stack* s)
{
	assert(s);
	return !s->size;
}